package com.junior.fixclub.util;

import android.os.Environment;
import android.text.TextUtils;

import com.junior.fixclub.ParamMaker;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;

public class DeviceUtil {
    public static String path = "/sdcard/fixclub/";
    public static void make(){
        makeAndFix("brand", ParamMaker.BRAND);
        makeAndFix("manufacturer",ParamMaker.MANUFACTURER);
        makeAndFix("model",ParamMaker.MODEL);
        makeAndFix("product",ParamMaker.PRODUCT);
        makeAndFix("name",ParamMaker.NAME);
        makeAndFix("device",ParamMaker.DEVICE);
        makeAndFix("sdk",ParamMaker.SDK);
        makeAndFix("release",ParamMaker.RELEASE_VERSION);

        makeAndFix("id",ParamMaker.ID);
        makeAndFix("language","");
        makeAndFix("region","");

        makeAndFix("tags",ParamMaker.TAGS);
        makeAndFix("fingerprint",ParamMaker.FINGERPRINT);
        makeAndFix("description",ParamMaker.DESCRIPTION);
        makeAndFix("host",ParamMaker.HOST);
        makeAndFix("incremental",ParamMaker.INCREMENTAL);
        makeAndFix("hardware",ParamMaker.HARDWARE);
        makeAndFix("abi",ParamMaker.CPU_ABI);
        makeAndFix("abi2",ParamMaker.CPU_ABI2);
        makeAndFix("platform",ParamMaker.PLATFORM);
        makeAndFix("serialno",ParamMaker.ANDROID_ID);

        makeAndFix("deviceid","");
        makeAndFix("meid",ParamMaker.MEID);
        makeAndFix("imei1",ParamMaker.IMEI1);
        makeAndFix("imei2",ParamMaker.IMEI2);

        makeAndFix("emui_version",ParamMaker.build_version_emui);
        makeAndFix("miui_version",ParamMaker.build_miui_version_name);
        makeAndFix("vivo_id",ParamMaker.build_vivo_build_display_id);
        makeAndFix("vivo_version",ParamMaker.build_vivo_product_version);
        makeAndFix("oppo_version",ParamMaker.build_opporom);
        makeAndFix("360_version",ParamMaker.build_uiversion_360);
        makeAndFix("jinli_version",ParamMaker.build_jinli_sv_version);
        makeAndFix("letv_version",ParamMaker.build_letv_release_version);
        makeAndFix("abilist",ParamMaker.ABI_LIST);

        makeAndFix("proc_cpuinfo","Processor       : AArch64 Processor rev 1 (aarch64)\n" +
                "processor       : 0\n" +
                "min_vddcx       : 400000\n" +
                "min_vddmx       : 490000\n" +
                "BogoMIPS        : 38.00\n" +
                "Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32\n" +
                "CPU implementer : 0x51\n" +
                "CPU architecture: 8\n" +
                "CPU variant     : 0x2\n" +
                "CPU part        : 0x201\n" +
                "CPU revision    : 1\n" +
                "\n" +
                "processor       : 1\n" +
                "min_vddcx       : 400000\n" +
                "min_vddmx       : 490000\n" +
                "BogoMIPS        : 38.00\n" +
                "Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32\n" +
                "CPU implementer : 0x51\n" +
                "CPU architecture: 8\n" +
                "CPU variant     : 0x2\n" +
                "CPU part        : 0x201\n" +
                "CPU revision    : 1\n" +
                "\n" +
                "processor       : 2\n" +
                "min_vddcx       : 400000\n" +
                "min_vddmx       : 490000\n" +
                "BogoMIPS        : 38.00\n" +
                "Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32\n" +
                "CPU implementer : 0x51\n" +
                "CPU architecture: 8\n" +
                "CPU variant     : 0x2\n" +
                "CPU part        : 0x205\n" +
                "CPU revision    : 1\n" +
                "\n" +
                "processor       : 3\n" +
                "min_vddcx       : 400000\n" +
                "min_vddmx       : 490000\n" +
                "BogoMIPS        : 38.00\n" +
                "Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32\n" +
                "CPU implementer : 0x51\n" +
                "CPU architecture: 8\n" +
                "CPU variant     : 0x2\n" +
                "CPU part        : 0x205\n" +
                "CPU revision    : 1\n" +
                "\n" +
                "CPU param       : 275 440 440 660 994 273 482 482 656 1173\n" +
                "Hardware        : Qualcomm Technologies, Inc MSM8996pro");//
        makeAndFix("proc_version","Linux version 3.18.31-g24a4020b992c (android-build@wphp5.hot.corp.google.com) (gcc version 4.9.x 20150123 (prerelease) (GCC) ) #1 SMP PREEMPT Thu Jun 29 16:55:05 UTC 2017");
        makeAndFix("cpuinfo_max_freq",ParamMaker.cpuinfo_max_freq);
        makeAndFix("cpuinfo_min_freq",ParamMaker.cpuinfo_min_freq);
        makeAndFix("random_boot_id", UUID.randomUUID().toString());
        makeAndFix("tty_drivers","/dev/tty             /dev/tty        5       0 system:/dev/tty\n" +
                "/dev/console         /dev/console    5       1 system:console\n" +
                "/dev/ptmx            /dev/ptmx       5       2 system\n" +
                "rfcomm               /dev/rfcomm   216 0-255 serial\n" +
                "g_serial             /dev/ttyGS    229 0-3 serial\n" +
                "usbserial            /dev/ttyUSB   188 0-511 serial\n" +
                "smd_tty_driver       /dev/smd      237 0-36 serial\n" +
                "msm_serial_hsl       /dev/ttyHSL   238 0-2 serial\n" +
                "msm_serial_hs        /dev/ttyHS    239 0-255 serial\n" +
                "pty_slave            /dev/pts      136 0-1048575 pty:slave\n" +
                "pty_master           /dev/ptm      128 0-1048575 pty:master");

        makeAndFix("null","");
    }

    public static void makeAndFix(String name,String data){
        if(TextUtils.isEmpty(data)){
            data = "";
        }
        File fileDir = new File(path);
        if (!fileDir.exists()) {
            fileDir.mkdir();
        }
        File file = new File(path+name);
        if (file.exists() && file.isFile()){
            boolean flag = file.delete();
        }
        try {
            if (file.createNewFile()){
                FileWriter fileWriter = new FileWriter(file.getAbsoluteFile(), true);
                fileWriter.write(data);
                fileWriter.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
